﻿using famails.bus;
using famails.dto;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace famails.BackEnd.page
{
    public class properties
    {
        public properties(string name, string text) { this.name = name; this.text = text; }
        public string name { get; set; }
        public string text { get; set; }
    }
    public partial class generate : System.Web.UI.Page
    {

        EventBUS eventBus = null;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnContinute_Click(object sender, EventArgs e)
        {
            try
            {
                String htmlForm = getHTMLCode();
                lblHTML.Visible = true;
                txtHTML.Text = htmlForm;
                txtHTML.Visible = true;
            }
            catch (Exception)
            {


            }
        }
        private UserLoginDTO getUserLogin()
        {
            if (Session["us-login"] != null)
            {
                return (UserLoginDTO)Session["us-login"];
            }
            return null;
        }
        protected String getHTMLCode()
        {
            try
            {
                int eventId = int.Parse(Request.QueryString["eventId"].ToString());
                int groupId = int.Parse(Request.QueryString["GroupId"].ToString());
                int UserID = getUserLogin().UserId;
                string requireTime = Session["RequireTime"] + "";

                eventBus = new EventBUS();
                DataTable tblEvent = eventBus.GetByID(eventId);

                String visibleField = "";
                String rowVisible = "";
                List<properties> items = getVisibleField();
                foreach (properties item in items)
                {
                    visibleField += item.name + " ";
                    rowVisible += "<tr>\n";
                    rowVisible += String.Format("<td>{0}</td>\n", item.text);
                    rowVisible += "</tr>";
                    rowVisible += "<tr>\n";
                    rowVisible += String.Format("<td><input name=\"{0}\" id=\"{0}\" type=\"text\" size=\"40\" /></td>\n", item.name);
                    rowVisible += "</tr>";
                }
                rowVisible += "<tr align=\"center\">\n";
                rowVisible += "<td><input name=\"btnSubmit\" id=\"btnSubmit\" type=\"submit\" value=\"Đăng ký\" /></td>\n";
                rowVisible += "</tr>\n";

                String rs = "";
                rs += "<form id=\"form1\" method=\"post\" action=\"http://famails.com/backend/page/register-event.aspx\" accept-charset=\"UTF-8\">\n";
                //rs += "<form id=\"form1\" method=\"post\" action=\"http://localhost:51054/backend/page/register-event.aspx\" accept-charset=\"UTF-8\">\n";
                rs += String.Format("<input name=\"UserId\" id=\"UserId\" type=\"hidden\" value=\"{0}\" />\n", UserID);
                rs += String.Format("<input name=\"eventId\" id=\"eventId\" type=\"hidden\" value=\"{0}\" />\n", eventId);
                rs += String.Format("<input name=\"visibleField\" id=\"visibleField\" type=\"hidden\" value=\"{0}\" />\n", visibleField.Trim());
                rs += String.Format("<input name=\"groupId\" id=\"groupId\" type=\"hidden\" value=\"{0}\" />\n", groupId);
                rs += String.Format("<input name=\"startDate\" id=\"startDate\" type=\"hidden\" value=\"{0}\" />\n", tblEvent.Rows[0]["StartDate"]);
                rs += String.Format("<input name=\"endDate\" id=\"endDate\" type=\"hidden\" value=\"{0}\" />\n", tblEvent.Rows[0]["EndDate"]);
                rs += String.Format("<input name=\"requireTime\" id=\"requireTime\" type=\"hidden\" value=\"{0}\" />\n", requireTime.Trim());
                rs += "<table>\n";
                rs += rowVisible;
                rs += "</table>\n";
                rs += "</form>\n";
                return rs;
            }
            catch (Exception)
            {

                return null;
            }
        }
        protected List<properties> getVisibleField()
        {
            List<properties> result = new List<properties>();
            properties item;
            if (rdoName2.Checked == true)
            {
                item=new properties("Name", "Họ tên");
                result.Add(item);
            }
            item = new properties("Email", "Email");
            result.Add(item);
            if (rdoJob2.Checked == true)
            {
                item = new properties("Job", "Nghề nghiệp");
                result.Add(item);
            }
            if (rdoCampany2.Checked == true)
            {
                item = new properties("Company", "Công ty");
                result.Add(item);
            }
            if (rdoGender2.Checked == true)
            {
                item = new properties("Gender", "Giới tính");
                result.Add(item);
            }
            if (rdobirthday2.Checked == true)
            {
                item = new properties("BirthDay", "Ngày sinh");
                result.Add(item);
            }
            if (rdoPhone2.Checked == true)
            {
                item = new properties("Phone", "Điện thoại");
                result.Add(item);
            }
            if (rdoAddress2.Checked == true)
            {
                item = new properties("Address1", "Địa chỉ");
                result.Add(item);
            }
            //if (rdoAddressTwo2.Checked == true)
            //{
            //    visibleField.Add("Address2", "Địa chỉ liên lạc");
            //}
            //if (rdoCity2.Checked == true)
            //{
            //    visibleField.Add("City", "Thành phố");
            //}
            //if (rdoProvince2.Checked == true)
            //{
            //    visibleField.Add("Province", "Quận/Huyện");
            //}
            //if (rdoZipCode2.Checked == true)
            //{
            //    visibleField.Add("ZipCode", "Mã vùng");
            //}
            //if (rdoCountry2.Checked == true)
            //{
            //    visibleField.Add("Country", "Quốc gia");
            //}
            //if (rdoFax2.Checked == true)
            //{
            //    visibleField.Add("Fax", "Fax");
            //}

            return result;
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect(Request.RawUrl, false);
        }
        protected void btnBackEvent_Click(object sender, EventArgs e)
        {
            Response.Redirect("create-event.aspx?eventId=" + Request.QueryString["eventId"], false);
        }

        public string bankimage(string email)
        {
            return "";
        }

    }
}